package com.xbongbong.paas.script.controller;

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.pojo.dto.BindPublicGroupDTO;
import com.xbongbong.paas.pojo.dto.ReturnCustomer2PublicAsyncDTO;
import com.xbongbong.paas.pojo.dto.ReturnCustomer2PublicDTO;
import com.xbongbong.paas.pojo.vo.ReturnCustomer2PublicVO;
import com.xbongbong.paas.service.ClueRuleService;
import com.xbongbong.paas.service.PublicGroupSyncService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.model.ClueRuleModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author lijiangren
 * @version v1.0
 * @date 2022/05/14 16:40
 * @since v1.0
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/script/publicGroupSync")
public class PublicGroupSyncScriptController {

    private static final Logger LOG = LoggerFactory.getLogger(PublicGroupSyncScriptController.class);
    @Lazy
    @Resource
    private PublicGroupSyncService publicGroupSyncService;

    /**
     *
     * 绑定所属公海分组脚本
     * @param bindPublicGroupDTO
     * @throws
     * @return
     * @author lijiangren
     * @date 2022-05-13 13 51
     * @since
     * @version
     */
    @RequestMapping(value = "/bindCustomerPublicGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String bindCustomerPublicGroup(@Valid BindPublicGroupDTO bindPublicGroupDTO, BindingResult br) {
        XbbResponse<BaseVO>  response;
        try {
            response = publicGroupSyncService.bindCustomerPublicGroupByScript(bindPublicGroupDTO);
        } catch (XbbException e) {
            response = new XbbResponse<>(e);
        }
        return JSON.toJSONString(response);
    }

    /**
     *
     * 绑定所属公海分组脚本
     * @param bindPublicGroupDTO
     * @throws
     * @return
     * @author lijiangren
     * @date 2022-05-13 13 51
     * @since
     * @version
     */
    @RequestMapping(value = "/bindCluePublicGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String bindCluePublicGroup(@Valid BindPublicGroupDTO bindPublicGroupDTO, BindingResult br) {
        XbbResponse<BaseVO>  response;
        try {
            response = publicGroupSyncService.bindCluePublicGroupByScript(bindPublicGroupDTO);
        } catch (XbbException e) {
            response = new XbbResponse<>(e);
        }
        return JSON.toJSONString(response);
    }



}
